package com.tz.actions;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.*;
import com.tz.entity.User;
import com.tz.service.UserService;
import com.tz.util.AcUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 * Created by Administrator on 2016/7/21.
 */
@Namespace(value = "/user")
public class UserAction extends ActionSupport{
    private User user;

    private UserService userService = AcUtil.getAc().getBean(UserService.class);


    /**
     * test
     */
    public void test(){
        userService.test();
    }


    @Validations(
            emails = {
                    @EmailValidator(
                            type = ValidatorType.SIMPLE,
                            fieldName = "user.email",
                            message = "邮箱格式不正确!"
                    )
            },
            requiredStrings ={
                    @RequiredStringValidator(
                            type = ValidatorType.SIMPLE,
                            fieldName = "user.email",
                            message = "邮箱不能为空"),
                    @RequiredStringValidator(
                            type = ValidatorType.SIMPLE,
                            fieldName = "user.password",
                            message = "密码不能为空")
            }
    )
    @Action(value = "login",results = {
            @Result(location = "/default.jsp"),
            @Result(name = INPUT,location = "/login.jsp")
    })
    public String login(){
        /*...*/
        return SUCCESS;
    }


    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
